<template>
	<div class="body">
		<div style="width: 100%; height: 100px">
			<a-row :gutter="[16, 8]">
				<a-col :span="4">
					<a-space>
						<a-button icon="left" @click.stop="goPrev" />
						<a-date-picker style="width: 130px" v-model:value="currentMonth" placeholder="选择日期"
							:allowClear="false" @change="onChangeDate" />
						<a-button icon="right" @click.stop="goNext" />
					</a-space>
				</a-col>
				<a-col :span="4">
					<span>姓名：</span>
					<a-input v-model="queryParam.realname" placeholder="请输入姓名" style="width: 180px" />
				</a-col>
				<a-col :span="4">
					<span>工号：</span>
					<a-input v-model="queryParam.workNo" placeholder="请输入工号" style="width: 180px" />
				</a-col>
				<!--        <a-col :span="4">-->
				<!--          <span>时间：</span>-->
				<!--          <a-date-picker v-model="time" style="width: 180px"/>-->
				<!--        </a-col>-->
				<a-col :span="4">
					<span>车间：</span>
					<j-multi-select-tag placeholder="请选择车间" v-model="queryParam.workshop" dictCode="workshop"
						style="width: 180px" />
				</a-col>
				<a-col :span="4">
					<span>班次：</span>
					<j-dict-select-tag placeholder="请选择班次" v-model="queryParam.shift" dictCode="shift"
						style="width: 180px" />
				</a-col>
				<a-col :span="4">
					<span>工序：</span>
					<j-dict-select-tag placeholder="请选择工序" v-model="queryParam.working_procedure" dictCode="working_procedure"
						style="width: 180px" />
				</a-col>
				<a-col :span="4">
					<span>品种：</span>
					<j-dict-select-tag placeholder="请选择品种" v-model="queryParam.productType"
						dictCode="crm_product_type_spun_yarn,product_type,id" style="width: 180px" />
				</a-col>
				<a-col :span="4">
					<span>工种：</span>
					<j-dict-select-tag placeholder="请选择品种" v-model="queryParam.workType" dictCode="work_type"
						style="width: 180px" />
				</a-col>
			</a-row>
			<div style="margin-top: 20px;">
				<a-space style="float: right;">
					<a-button @click="handleExportXls('推细纱')" type="default" icon="export">导出报表</a-button>
					<a-button @click="handleSearch()" type="primary">搜索</a-button>
					<a-button @click="handleAdd" type="primary">新增</a-button>
					<a-button type="primary" @click="generateSalary">生成报表</a-button>
					<!-- <a-button>导出报表</a-button> -->
					
					<!-- <a-button>导出长度报表</a-button> -->
					<!-- <a-button type="primary">自选生产薪资报表</a-button> -->
				</a-space>
			</div>
		</div>
		<div style="margin-top: 15px;">
			<a-table :columns="columns" rowKey="id" :data-source="dataSource" :scroll="{ x: 6500 }"
				:pagination="ipagination" :loading="loading"
				:rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
				@change="handleTableChange">
				<!-- 操作 -->
				<a-space slot="action" slot-scope="text, record">
					<template>
						<a-button style="padding: 0px" type="link" icon="edit" @click="handleEdit(record)">编辑</a-button>
						<a-popconfirm title="确认要删除吗?" @confirm="() => handleDelete(record.id)">
							<a-button style="color: red; padding: 0px" type="link" icon="delete">删除</a-button>
						</a-popconfirm>
					</template>
				</a-space>
			</a-table>
		</div>
		<jia-ban-modal ref="modalForm" @ok="modalFormOk"></jia-ban-modal>
	</div>
</template>

<script>
	import {
		JeecgListMixin
	} from '@/mixins/JeecgListMixin'
	import JiaBanModal from './modules/JiaBanModal'
	import {
		copyYesterdayDailyPlan,
		getGenerateSalary
	} from '../../../api/customApi'
	import moment from 'moment'
	const path = '/crm_salary_excel_spun_yarn_push_rove/crmSalaryExcelSpunYarnPushRove'
	export default {
		mixins: [JeecgListMixin],
		components: {
			JiaBanModal
		},
		data() {
			return {
				currentMonth: moment(),
				columns,
				queryParam: {
					planTime: moment().format('YYYY-MM-DD')
				},
				url: {
					list: path + '/list',
					delete: path + '/delete',
					deleteBatch: path + '/deleteBatch',
					exportXlsUrl: '/crm_salary_excel_spun_yarn_push_rove/crmSalaryExcelSpunYarnPushRove/exportExcel'
				}
			}
		},
		methods: {
			goPrev() {
				var newMonth = moment(this.currentMonth).subtract(1, 'day')
				this.currentMonth = newMonth
				this.queryParam.planTime = this.currentMonth.format('YYYY-MM-DD')
				this.searchQuery()
			},
			goNext() {
				var newMonth = moment(this.currentMonth).add(1, 'day')
				this.currentMonth = newMonth
				this.queryParam.planTime = this.currentMonth.format('YYYY-MM-DD')
				this.searchQuery()
			},
			onChangeDate(date, dateString) {
				this.queryParam.planTime = dateString
				this.searchQuery()
			},
			changeObject() {},
			refresh() {
				this.searchQuery()
			},
			handleSearch() {
				this.searchQuery()
				this.visible = false
			},
			handleCancel() {
				this.visible = false
			},
			handleReset() {
				this.searchReset()
			},
			add() {
				this.visable1 = true
			},
			detail(record) {},
			onChangePage(e) {
				this.ipagination.current = e
				this.loadData()
			},
			generateSalary() {
				let query = {
					// planTime:this.currentMonth
					planTime: this.queryParam.planTime
				}
				getGenerateSalary(query).then(res => {
					if (res.success) {
						this.$message.success('生成成功')
						this.searchQuery()
					}
				})
			},
			btnImport() {},
			btnExport() {}
		}
	}

	const columns = [{
			title: '台位',
			width: 200,
			dataIndex: 'pedestal',
			key: 'pedestal',
			fixed: 'left'
		},
		{
			title: '日期',
			width: 100,
			dataIndex: 'createTime',
			key: 'createTime',
			fixed: 'left'
		},
		{
			title: '细纱车间',
			width: 100,
			dataIndex: 'workshop',
			key: 'workshop',
			fixed: 'left'
		},
		{
			title: '络筒车间',
			width: 100,
			dataIndex: 'workshopSpooling',
			key: 'workshopSpooling',
			fixed: 'left'
		},
		{
			title: '班次',
			width: 100,
			dataIndex: 'shift_dictText',
			key: 'shift',
			fixed: 'left'
		},
		{
			title: '时间',
			width: 100,
			dataIndex: 'workHours',
			key: 'workHours',
			fixed: 'left'
		},
		{
			title: '工号',
			dataIndex: 'workNo',
			key: 'workNo',
			width: 150
		},
		{
			title: '姓名',
			dataIndex: 'realname',
			key: 'realname',
			width: 150
		},
		{
			title: '工序',
			dataIndex: 'workType',
			key: 'workType',
			width: 150
		},
		{
			title: '类型',
			dataIndex: 'productCategory',
			key: 'productCategory',
			width: 200
		},
		{
			title: '品种',
			dataIndex: 'productType_dictText',
			key: 'productType',
			width: 150
		},
		{
			title: '台位起',
			dataIndex: 'pedestalStart',
			key: 'pedestalStart',
			width: 150
		},
		{
			title: '台位终',
			dataIndex: 'pedestalEnd',
			key: 'pedestalEnd',
			width: 150
		},
		{
			title: '数量',
			dataIndex: 'machinesNum',
			key: 'machinesNum',
			width: 150
		},
		{
			title: '8小时台数',
			dataIndex: 'machinesNumEightHours',
			key: 'machinesNumEightHours',
			width: 150
		},
		{
			title: '单价',
			dataIndex: 'unitPrice',
			key: 'unitPrice',
			width: 150
		},
		{
			title: '工资',
			dataIndex: 'wages',
			key: 'wages',
			width: 150
		},
		{
			title: '其它补贴',
			dataIndex: 'otherSubsidies',
			key: 'otherSubsidies',
			width: 150
		},
		{
			title: '合计工资',
			dataIndex: 'totalWages',
			key: 'totalWages',
			width: 150
		},
		{
			title: '备注',
			dataIndex: 'remark',
			key: 'remark',
			width: 150
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center',
			scopedSlots: {
				customRender: 'action'
			},
			fixed: 'right'
		}
	]
</script>
<style scoped>
	.body {
		background: #fff;
		padding: 15px;
	}
</style>